package com.example.messagedemo.controller;

import com.example.messagedemo.producer.MessageProducer;
import com.example.messagedemo.request.SendTopicMessageRequest;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {
    final public MessageProducer producer;

    public MessageController(MessageProducer producer) {
        this.producer = producer;
    }

    @RequestMapping(value = "/api/mq/send_message")
    public String sendMessage(@ModelAttribute SendTopicMessageRequest request) throws Exception {
        producer.sendCommonMessage(request);
        return "send success";
    }

    @RequestMapping(value = "/api/mq/sync_send_message")
    public String sendSyncMessage(@ModelAttribute SendTopicMessageRequest request) throws Exception {
        producer.sendSyncMessage(request);
        return "send success";
    }

    @RequestMapping(value = "/api/mq/send_oneWay_message")
    public String sendOneWayMessage(@ModelAttribute SendTopicMessageRequest request) throws Exception {
        producer.sendOneWay(request);
        return "send success";
    }
}

